package com.project.class3_28.bean.impl;

import com.project.class3_28.bean.StudentBean;
import com.project.class3_28.dao.IStudentDao;

import java.time.LocalDate;
import java.util.List;

public class StudentDaoImpl extends BaseDao implements IStudentDao {
    @Override
    public void add(StudentBean student) {
        this.updateDB("INSERT INTO t_student01(studentName,sex,phone,birthday,email)values(?,?,?,?,?)",
                student.getStudentName(),student.getSex(),student.getPhone(),student.getBirthday(),student.getEmail());
    }

    @Override
    public void del(int id) {
        this.updateDB("delete from t_student01 where id=?",id);
    }

    @Override
    public void update(int id, String phone) {
        this.updateDB("update t_student01 set phone=? where id=?",phone,id);
    }

    @Override
    public List<StudentBean> findAll() {
        return this.findDB("select * from t_student01",StudentBean.class);
    }

    @Override
    public List<StudentBean> findByName(String name) {
        return this.findDB("select * from t_student01 where studentName like ?",StudentBean.class,"%"+name+"%");
    }

    @Override
    public StudentBean findById(int id) {
        return (StudentBean)this.findDB("select * from t_student01 where id=?",StudentBean.class,id).get(0);
    }

    public static void main(String[] args) {
        IStudentDao dao = new StudentDaoImpl();
//        dao.add(new StudentBean("蟑螂","男",
//                "15578914756", LocalDate.parse("2001-01-02"),"4465464@qq.com"));
//        dao.del(7);
//        dao.update(6,"18299988855");
        System.out.println(dao.findAll());
//        System.out.println(dao.findByName("张"));
//        System.out.println(dao.findById(2));
    }
}
